import 'package:dio/dio.dart' hide Headers;
import 'package:flutter_book_store/beans/books_entity.dart';
import 'package:flutter_book_store/net/apis.dart';
import 'package:flutter_book_store/net/dio_options.dart';
import 'package:flutter_book_store/net/mock_adapter.dart';
import 'package:get/get.dart';

class BookModel extends GetxController {
  var datas = List<BooksList>().obs;
  var tempData = List();

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
    getBookList();
  }

  void getBookList() async {
    //未做封装
    final dio = Dio(DioOptions.options);
    // dio.httpClientAdapter = MockAdapter();
    dio.interceptors.add(DioInterceptor());
    final api = RestClient(dio, baseUrl: MockAdapter.mockBase);
    api.getBookList('', 1, 3).then((value) {
      print(value);
      datas.clear();
      datas.addAll(value.data.xList);
    }).catchError((Object obj) {
      switch (obj.runtimeType) {
        case DioError:
          final res = (obj as DioError).response;
          break;
        default:
      }
    });
  }
}
